package com.hrl.Test;

import com.hrl.domain.Dept;
import com.hrl.domain.Employee;
import com.hrl.service.DeptService;
import com.hrl.service.EmpService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.Date;
import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class EmpTest {

    @Autowired
    private EmpService empService;

    @Autowired
    private DeptService deptService;

    @Test
    public void testFindAll(){
        List<Employee> all = empService.findAll();
        for (Employee employee : all) {
            System.out.println(employee);
        }
    }

    @Test
    public void testFindById(){
        Employee byId = empService.findById(1);
        System.out.println(byId);
    }

    @Test
    public void testSave(){
        Employee employee = new Employee();
        employee.setDept_id(2);
        employee.setEmp_name("小羊");
        employee.setJob_name("销售经理");
        employee.setJoin_date(new Date());
        employee.setTelephone("12345678910");

        empService.save(employee);
    }

    @Test
    public void testUpdate(){
        Employee employee = new Employee();
        employee.setEmp_id(4);
        employee.setDept_id(1);
        employee.setEmp_name("小羊");
        employee.setJob_name("客户经理");
        employee.setJoin_date(new Date());
        employee.setTelephone("12345678910");

        empService.update(employee);
    }

    @Test
    public void testDelete(){
        empService.delete(4);
    }

    @Test
    public void testDept(){
        Dept byId = deptService.findById(1);
        System.out.println(byId);
        Dept byId2 = deptService.findById(2);
        System.out.println(byId2);
    }
}
